var apiTester = require('./tester/apiTester');
apiTester.config({showRes:true});

var getTestTask = [
  {
    url:'/api/hospitals/edit/5977e69df16cf60bf0324312',
    reqData:{
    },
    cb:function(res,testConfig){
      //console.log('res...',res['body']);
      var hospital = res['body'];
      if(hospital._id == '5977e69df16cf60bf0324312')
        console.log('getTest:',testConfig.url,'Test passed.');
    }
  },
];

var postTestTask = [
  {
    url:'/api/userhislist',
    reqData:{
      "uid": "59780a610228081ef4afae31",
      "email": "tht11@sina.com",
      "name": "tht11",
      "role": "admin",
      "loclist": []
    },
    cb:function(res,testConfig){
      if(res['body'][0]._id == '5977e400febeb521d08b1680')
        console.log('postTest:',testConfig.url,'Test passed.');
      else{
        console.log('postTest:',testConfig.url,'Test failed.');
      }
    }
  },
  {
    url:'/api/userhislist',
    reqData:{
      "uid": "597aad2a1fd77d0a10c35311",
      "email": "tht12@sina.com",
      "name": "tht12",
      "role": "view",
      "loclist": []
    },
    cb:function(res,testConfig){
      console.log('postTest:',testConfig.url,res.body);
    }
  },
  {
    url:'/api/hospitals',
    reqData:{
      hcode:'newCodexx',
      name:'新医院名123'
    },
    cb:function(res,testConfig){
      console.log('postTest:',testConfig.url,res.body);
    }
  },
]

var putTestTask = [
  {
    url:'/api/hospitals/edit/5977e69df16cf60bf0324312',
    reqData:{
      hcode:'newCode',
      name:'新医院名'
    },
    cb:function(res,testConfig){
      //if()
      console.log('putTest:',testConfig.url,`test ${res['body'].ok==1?'passed':'failed'}`);
    }
  },
];

var deleteTestTask = [
  {
    url:'/api/hospitals/5977e69df16cf60bf0324312',
    reqData:{
    },
    cb:function(res,testConfig){
      console.log('deleteTest:',testConfig.url,`test ${res.body.status=='0'?'passed':'failed'}`);
    }
  },
];

//*
for(let tt of getTestTask){
  //tt.url = testHost+tt.url;
  apiTester.doGetTest(tt);
}//*/

//*
for(let tt of postTestTask){
  //tt.url = testHost+tt.url;
  apiTester.doPostTest(tt);
}//*/

//*
for(let tt of putTestTask){
  //tt.url = testHost+tt.url;
  apiTester.doPutTest(tt);
}//*/

//*
for(let tt of deleteTestTask){
  //tt.url = testHost+tt.url;
  apiTester.doDeleteTest(tt);
}//*/

